1 // Equipo Poncho, Carriel y Ruana
22 template <class T
> string
toStr(const T
&x
)
23 { stringstream s
; s
<< x
; return s
.str(); }
24 template <class T
> int toInt(const T
&x
)
25 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
27 #define For(i, a, b) for (int i=(a); i<(b); ++i)
28 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
29 #define D(x) cout << #x " = " << (x) << endl;
31 const double EPS
= 1e-9;
33 int cmp(double x
, double y
= 0, double tol
= EPS
) {
34 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
37 #define INPUT_FILE "compression"
39 const int MAXBASES
= 105, oo
= 1 << 28;
43 int bit
[20]; // bit[i] = index of term i in the document
45 int dp
[MAXBASES
][1 << 16];
47 int been
[MAXBASES
][1 << 16];
52 for (int i
= 0; i
< 16; ++i
){
53 printf("%d", !!(x
& (1 << i
)));
59 been
[0][0] = currentRun
;
61 for (int i
= 0; i
< B
; ++i
) {
62 for (int mask
= 0; mask
< (1 << 16); ++mask
) {
63 if (been
[i
][mask
] < currentRun
) continue;
66 dp
[i
+1][mask
] = min(dp
[i
+1][mask
], dp
[i
][mask
]);
67 dp
[i
+1][mask
| base
] = min(dp
[i
+1][mask
| base
], dp
[i
][mask
] + 1);
74 //For(i, 0, B) if (compatible(bases[i])) printf("Base i=%d: %d\n", i, maskOfBase(bases[i]));
76 // for (int i = 0; i < 16; ++i) {
77 // printf("bit[%d] = %d\n", i, bit[i]);
81 if (ans
>= oo
) ans
= 0;
86 freopen(INPUT_FILE
".in", "r", stdin
);
87 while (cin
>> B
>> D
) {
88 if (B
== 0 and D
== 0) break;
89 for (int i
= 0; i
< B
; ++i
) {
97 //printf("base[i=%d] = %d\n", i, bases[i]);
100 for (int j
= 0; j
< D
; ++j
) {
105 int x
; cin
>> x
; x
--;
108 //printf("doc = %d\n", doc);
110 if (j
+ 1 < D
) printf(" ");